* Load the data file -----------------------------------------------------------

	if "$individual_run" != "Yes" {
	di "Program Stopped: Make sure you load the parameters in master.do"
	e
	}

* Function ---------------------------------------------------------------------

* Plot group header
	capture: program drop plot_group
	program plot_group
	args filename title 
			
			* Write Expression
			file open table using `filename', write replace
			file write table ///
			"\begin{figure}[H]"			_n ///
			"\caption{`title'} "	_n ///
			"\vspace{0.5cm}"			_n 
	end
	
* Plot group content

	capture: program drop plot_individual_vertical
	program plot_individual_vertical
	args outcome_matrix mul outcome_title min_height scale L U loc index 
			
			* Catching values from matrix
			foreach period in 1_4 5_8 9_12 {
				
				* Get and format estimates
				mat temp = `outcome_matrix'_months_`period'_t
				
					* ITT
					local ITT_`period' = temp[1,2] * `mul'
					local SE_`period'  : di %5.3f temp[1,3] * `mul'
					
					* CE Band
					local LB_`period'  = (temp[1,2]- 1.645 * temp[1,3]) * `mul'
					local UB_`period'  = (temp[1,2]+ 1.645 * temp[1,3]) * `mul'
					
					* Display values
						
						* P-values and Q-values
						local p   =  temp[1,4]
						local q   =  temp[1,5]
						
						local p_`period'   :  di %5.3f temp[1,4]
						local q_`period'   :  di %5.3f temp[1,5]
						
						* Stars for p_values
						local star_p_`period' = ///
							cond(`p'<0.01,"***", cond(`p'<0.05,"**", ///
							cond(`p'<0.1,"*", cond(`p'>=0.1, "", ""))))
						
						local star_q_`period' = ///
							cond(`q'<0.01,"***", cond(`q'<0.05,"**", ///
							cond(`q'<0.1,"*", cond(`q'>=0.1, "", ""))))
							
						* Label for ITT
						local ITT_`period'_disp   :  di %5.3f `ITT_`period''
			}
			
			* Write Expression for overall
			file write table ///
			"\centering" _n ///
			"\tikzset{" _n ///
			"mynode/.style={" _n ///
			", align=center" _n ///
			", execute at begin node=\setlength{\baselineskip}{0.1em}" _n ///
			"}" _n ///
			"}" _n ///
			"\begin{tikzpicture}[xscale = 3.5, yscale = `scale', shading=black]" _n ///
			_n ///
			"\draw [dotted, color = gray] (0.5,0) -- (3.5,0);" _n ///
			"\draw [dotted, color = white] (0.5,`L') -- (0.5,`U');" _n ///
			_n ///
			"\draw (0.5,0) node[left]{\small \color{gray} 0};" _n ///
			"\draw (0.5,`L') node[left]{\small \color {white}`L'};" _n ///
			"\draw (0.5,`U') node[left]{\small \color{white} `U'};" _n ///
			_n ///
			"\draw (0.25,`loc') node[right, label={[align=left]right:{\textbf{`outcome_title'}}}]{};" _n ///
			"\draw (1,`min_height') node(M)[below]{\small Months 1-4};" _n ///
			"\node[align=center,above=0.11cm] (Ml) at (M) {\scriptsize \color{black} Key Evaluation Period};" _n ///
			"\draw (2.5,`min_height') node(N)[below]{\small \color{white} X};" _n ///
			"\node[align=center,above=0.11cm] (Nl) at (N) {\scriptsize \color{${gray_color}} Additional Periods};" _n ///
			"\draw (2,`min_height') node[below]{\small \color{${gray_color}} Months 5-8};" _n ///
			"\draw (3,`min_height') node[below]{\small \color{${gray_color}} Months 9-12};" _n ///_n ///
			"\node [draw, circle, fill=black, scale=0.5] (A) at (1,`ITT_1_4') {};" _n ///
			"\node[mynode](a)[right] at (1.05, `ITT_1_4') {\small `ITT_1_4_disp' \\ \tiny \color{white} space } ;" _n ///
			"\node[mynode][align=center,anchor=north] (ap) at (a) {\tiny (`p_1_4')`star_p_1_4' " ///
															   "\\ \tiny [`q_1_4']`star_q_1_4'};" _n ///
			"\draw[|-|, line width=0.250mm, color={black}] (1,`LB_1_4') -- (1, `UB_1_4');" _n ///
			_n ///
			"\node [draw, circle, fill={${gray_color}}, color={${gray_color}}, scale=0.5] (A) at (2,`ITT_5_8') {};" _n ///
			"\node[mynode](a)[right] at (2.05, `ITT_5_8') {\small \color{${gray_color}} `ITT_5_8_disp' \\ \tiny \color{white} space};" _n ///
			"\node[mynode][align=center,anchor=north] (ap) at (a) {\tiny \color{${gray_color}} (`p_5_8')`star_p_5_8' " ///
															   "\\ \tiny  \color{${gray_color}}[`q_5_8']`star_q_5_8'};" _n ///
			"\draw[|-|, line width=0.250mm, color={${gray_color}}] (2,`LB_5_8') -- (2, `UB_5_8');" _n ///
			_n ///
			"\node [draw, circle, fill={${gray_color}}, color={${gray_color}}, scale=0.5] (A) at (3,`ITT_9_12') {};" _n ///
			"\node[mynode](a)[right] at (3.05, `ITT_9_12') {\small \color{${gray_color}} `ITT_9_12_disp' \\ \tiny \color{white} space };" _n ///
			"\node[mynode][align=center,anchor=north] (ap) at (a) {\tiny \color{${gray_color}} (`p_9_12')`star_p_9_12' " ///
															   "\\ \tiny \color{${gray_color}} [`q_9_12']`star_q_9_12'};" _n ///
			"\draw[|-|, line width=0.250mm, color={${gray_color}}] (3,`LB_9_12') -- (3, `UB_9_12');" _n ///
			_n ///
			"\end{tikzpicture}" _n ///
			_n ///
			"\vspace{0.75cm}" _n 
	end
	
	* Plot group end
	capture: program drop plot_end
	program define plot_end 
		args note ref
		di "C"
		file write table ///
			"\begin{minipage}{1\textwidth} \linespread{0.75}\selectfont" _n ///
			"{\footnotesize `note'}" _n ///
			"\end{minipage}" _n ///
			"\label{fig_admin_outcome}" _n ///
			"\end{figure}" _n 
		file close table
	end
	
* Plot notes -------------------------------------------------------------------
capture: program drop write_end
program write_end
args N1 N2 N3

gl plot_note_one_reg "\singlespacing \textbf{Notes.} This figure examines the effect of Sit-D training in the key evaluation period and two additional periods, by presenting estimates of equation \eqref{eqn:Dynamic_ITT}. Each panel is a different regression. Twelve monthly post-training observations are included for each officer. N=`N1'. All regressions include stratum fixed effects, month fixed effects, and additional officer-level covariates (see notes to Table 3). The plots show coefficients on the interaction of Sit-D with period indicators along with 90\% Confidence Intervals. Observed p-values, based on standard errors clustered on officer, are in parentheses. Multiple-inference corrected q-values that adjust for the false discovery rate within each four-month period and across outcomes in a family are in square brackets. Uses of non-lethal force and discretionary arrests constitute the Adverse Policing Outcomes Family, and officer injuries and the officer activities index constitute the Officer Safety and Activity Family. ***is significant at the 1\% level, ** is significant at the 5\% level, and * is significant at the 10\% level." 	

end 

* Technical notes --------------------------------------------------------------

	/* The regression in this file is of the form:
	reg NLU $month_list_4m $month_treatment_list_4m ///
	${picked5a} i.strata i.year_month, vce(cluster employee_id)
	*/
	
* Main table -------------------------------------------------------------------
		
		gl gray_color rgb:black,9;white,5
		
		plot_group ///
		${report_folder}/Admin_plot_main_outcomes_alternative.txt ///
		"Outcomes over Additional Periods" 
									//outcome 		mul 		outcome_title 					min 	scale 	L 		U 		loc 	index
		plot_individual_vertical 	q_p_h4_NLU		1000		"Uses of non-lethal force"      -25   	0.075  	-20   	10 		12
		plot_individual_vertical 	q_p_h4_DAR 		1000		"Discretionary arrests" 		-25   	0.075  	-20   	10 		12
		plot_individual_vertical 	q_p_h4_OI		1			"Officer injuries (days off)" 	-1.55 	1.1  	-1.5    1		1.15
		plot_individual_vertical 	q_p_h4_AI		1			"Officer activities (index)" 	-0.1   	16  	-0.05 	0.05 	0.075
		
		local N : di %9.0fc q_p_h4_AI_months_1_4_t[1,6]
		write_end `N'
		
		plot_end "$plot_note_one_reg"
		